package cn.com.red;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;


public class ProxyTest implements InvocationHandler{
	private Object target;
	
	public ProxyTest(Object target){
		this.target = target;
	}
	
	public <T> T proxyInstance(){
		return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
	}
	
	@Override
	public Object invoke(Object arg0, Method arg1, Object[] arg2)
			throws Throwable {
		System.out.println("do something before ...");
		Object ret = arg1.invoke(target, arg2);
		System.out.println("do something after ...");
		return ret;
	}
}
